#include<bits/stdc++.h>
#define int long long
using namespace std;
int T,n,m,ll,vv,d[100005],v[100005],a[100005],b[100005],ans1,ans2,minr;
const int inf=100000000;
vector<pair<int,int> >g;
int getspeed(int vvv,int aaa,int lll){
    if(!aaa)return vvv*vvv;
    else return vvv*vvv+2*lll*aaa;
}
signed main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--){
        cin>>n>>m>>ll>>vv;vv*=vv;ans1=n;ans2=0LL;g.clear();
        for(int i=1;i<=n;i++)cin>>d[i]>>v[i]>>a[i];
        for(int i=1;i<=m;i++)cin>>b[i];
        for(int i=1;i<=n;i++){
            if(a[i]<0){
                if(d[i]>b[m]){ans1--;continue;}
                int pl=lower_bound(b+1,b+m+1,d[i])-b;
                if(getspeed(v[i],a[i],b[pl]-d[i])<=vv){ans1--;continue;}
                int l=pl,r=m;
                while(l<r){
                    int mid=(l+r+1)/2;
                    if(getspeed(v[i],a[i],b[mid]-d[i])<=vv)r=mid-1;
                    else l=mid;
                }
                g.push_back(make_pair(pl,l));//cout<<pl<<" "<<l<<"\n";cout<<g.size()<<"\n";
            }else{
                if(d[i]>b[m]){ans1--;continue;}
                int pl=lower_bound(b+1,b+m+1,d[i])-b;
                if(getspeed(v[i],a[i],b[m]-d[i])<=vv){ans1--;continue;}
                int l=pl,r=m;
                while(l<r){
                    int mid=(l+r)/2;
                    if(getspeed(v[i],a[i],b[mid]-d[i])<=vv)l=mid+1;
                    else r=mid;
                }
                g.push_back(make_pair(l,m));//cout<<pl<<" "<<l<<"\n";cout<<g.size()<<"\n";
            }
        }sort(g.begin(),g.end());g.push_back(make_pair(inf,inf));minr=inf;//cout<<"---\n";
        for(int i=0;i<g.size();i++){
            //cout<<g[i].first<<" "<<g[i].second<<"\n";
            if(minr<g[i].first){ans2++;/*cout<<minr<<"\n";*/minr=inf;}
            minr=min(minr,g[i].second);
        }cout<<ans1<<" "<<m-ans2<<"\n";
    }
}
